package com.wenhai.spring.aop.features;

import com.wenhai.spring.aop.features.interceptor.EchoServiceMethodInterceptor;
import com.wenhai.spring.aop.features.pointcut.EchoServicePointcut;
import com.wenhai.spring.aop.features.service.DefaultEchoServiceImpl;
import com.wenhai.spring.aop.features.service.EchoService;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;

/**
 * @ClassName PointcutAPIDemo
 * @Description
 * @Author 谢文海
 * @Date 2021/3/5 20:10
 * @Version 1.0
 **/
public class PointcutAPIDemo {
    public static void main(String[] args) {
        EchoServicePointcut pointcut = new EchoServicePointcut("echo", EchoService.class);

        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, new EchoServiceMethodInterceptor());

        ProxyFactory proxyFactory = new ProxyFactory(new DefaultEchoServiceImpl());
        proxyFactory.addAdvisor(advisor);
        EchoService echoService = (EchoService) proxyFactory.getProxy();
        System.out.println(echoService.echo("hello world"));


    }
}
